﻿@{ ViewBag.Title = "Add";
    Layout = "~/Areas/Shared/_LayuiForm.cshtml"; }

<form class="layui-form">
    <div class="layui-form-item">
        <label class="layui-form-label">所属流程</label>
        <div class="layui-input-block">
            <input style="display:none" name="tbid" id="tbid" value="@ViewBag.tbid">
            <input style="display: none" name="flowId" id="flowId" value="@ViewBag.flowId">
            <input type="text" name="FlowName" id="FlowName" class="layui-input" readonly="readonly" value="@ViewBag.name">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">步骤编码</label>
        <div class="layui-inline">
            <input type="text" name="PrcsNo" id="PrcsNo" placeholder="必填 " autocomplete="off" class="layui-input" lay-verify="required|id" maxlength="30">
        </div>
        <div class="layui-inline">
            <select name="AutoType" id="AutoType" lay-filter="selectfilter">
                <option value="">⇓自动生成编码</option>
                <option value="英文">英文</option>
                <option value="全拼">全拼</option>
                <option value="首拼">首拼</option>
            </select>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label required">步骤序号</label>
            <div class="layui-input-block">
                <input type="text" name="PrcsOrder" id="PrcsOrder" placeholder="必填 序号" autocomplete="off" class="layui-input" lay-verify="required|number" maxlength="3">
            </div>
        </div>
        <div class="layui-inline">
            <input type="hidden" name="BFirst" value="2">
            <input type="checkbox" id="BFirst" checked="checked" name="BFirst" value="1" title="新建步骤（即流程步骤第1步）">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">步骤名称</label>
        <div class="layui-input-block">
            <input type="text" name="PrcsName" id="PrcsName" placeholder="必填 步骤名称" autocomplete="off" class="layui-input" lay-verify="required" maxlength="30">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">可写字段</label>
        <div class="layui-input-block">
            <input style="display: none" name="PrcsIndex" id="PrcsIndex">
            <textarea placeholder="可写字段...点击选择" value="" name="PrcsIndex_Exa" id="PrcsIndex_Exa" class="layui-textarea" readonly="readonly"></textarea>
            <span style="position: absolute;bottom: 6px; right: 5px;">
                <a href="javascript:;"><i class="fa fa-check-circle" id="PrcsIndex2">选择</i></a>
                <a href="javascript:;"><i class="fa fa-check" id="allPrcsIndex">所有</i></a>
            </span>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">保密字段</label>
        <div class="layui-input-block">
            <input style="display: none" name="HiddenIndex" id="HiddenIndex">
            <textarea placeholder="保密字段...点击选择" value="" name="HiddenIndex_Exa" id="HiddenIndex_Exa" class="layui-textarea" readonly="readonly"></textarea>
            <span style="position: absolute;bottom: 6px; right: 5px;">
                <a href="javascript:;"><i class="fa fa-check-circle" id="HiddenIndex2">选择</i></a>
            </span>
        </div>
    </div>
    <fieldset class="table-fieldset">
        <legend>授权范围由人员、单位及角色的合集确定，即满足人员、单位及角色其中一项便能办理</legend>
        <div style="margin: 5px 5px 5px 5px">
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <input style="display: none" name="PrcsUser" id="PrcsUser">
                    <textarea placeholder="人员...点击选择" value="" name="PrcsUser_Exa" id="PrcsUser_Exa" class="layui-textarea" readonly="readonly"></textarea>
                    <span style="position: absolute;bottom: 6px; right: 5px;">
                        <a href="javascript:;"><i class="fa fa-check-circle" id="PrcsUser2">选择</i></a>
                        <a href="javascript:;"><i class="fa fa-check" id="allPrcsUser">所有</i></a>
                    </span>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <input style="display: none" name="PrcsDept" id="PrcsDept">
                    <textarea placeholder="部门...点击选择" value="" name="PrcsDept_Exa" id="PrcsDept_Exa" class="layui-textarea" readonly="readonly"></textarea>
                    <span style="position: absolute;bottom: 6px; right: 5px;">
                        <a href="javascript:;"><i class="fa fa-check-circle" id="PrcsDept2">选择</i></a>
                        <a href="javascript:;"> <i class="fa fa-check" id="allPrcsDept">所有</i></a>
                    </span>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <input style="display: none" name="PrcsPriv" id="PrcsPriv">
                    <textarea placeholder="角色...点击选择" value="" name="PrcsPriv_Exa" id="PrcsPriv_Exa" class="layui-textarea" readonly="readonly"></textarea>
                    <span style="position: absolute;bottom: 6px; right: 5px;">
                        <a href="javascript:;"><i class="fa fa-check-circle" id="PrcsPriv2">选择</i></a>
                        <a href="javascript:;"><i class="fa fa-check" id="allPrcsPriv">所有</i></a>
                    </span>
                </div>
            </div>
        </div>
    </fieldset>
    <br />
    <div class="layui-form-item">
        <label class="layui-form-label">回退选项</label>
        <div class="layui-input-block">
            <select name="AllowBack" id="AllowBack" lay-filter="AllowBack">
                <option value='1'> 不允许</option>
                <option value='2'> 允许回退上一步骤</option>
                <option value='3' selected> 允许回退之前步骤</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">公共附件</label>
        <input style="display: none" name="BAttachment" id="BAttachment">
        <div class="layui-inline">
            <input type="hidden" name="A1" value="2">
            <input type="hidden" name="A2" value="2">
            <input type="hidden" name="A3" value="2">
            <input type="checkbox" id="A1" name="A1" value="1" checked="checked" lay-filter="BAttachment" title="新建权限">
            <input type="checkbox" id="A2" name="A2" value="1" checked="checked" lay-filter="BAttachment" title="删除权限">
            <input type="checkbox" id="A3" name="A3" value="1" checked="checked" lay-filter="BAttachment" title="下载权限">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label"> </label>
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="add">新增</button>&nbsp;
            <input type="checkbox" id="continue" title="连续新增">
        </div>
    </div>
</form>
<script>
    layui.use(["form", "exLayer", "exUtils"], function () {
        let form = layui.form;
        let layer = layui.layer;
        let exLayer = layui.exLayer;
        let exUtils = layui.exUtils;

        let $ = layui.$;

        form.render(); //初始化表单，要加上，不然刷新部分组件可能会不加载

        form.verify({
            id: function (value, item) {
                if (!new RegExp("^[a-zA-Z]+[a-zA-Z0-9]+$").test(value)) {
                    return '编码由英文字符和数字组成，并以字母开头，不得包含中文、空格及其他字符';
                }
            }
        });

        form.on("submit(add)", function (data) {
            exUtils.ajax("/SysFlow/FlowPrcs/AddPrcs", "post", data.field, true).done(function (response) {
                exLayer.greenTickMsg(response.message, function () {
                });
                parent.layui.table.reload('tableId', { url: "/SysFlow/FlowPrcs/GetListByFId?id=" + $(window.parent.document).find("#flowId").val() });
                parent.layer.close(parent.layer.getFrameIndex(window.name));
            }).fail(function (error) {
                console.log(error);
            });
            return false;
        });

        //自动生成编码
        form.on('select(selectfilter)', function (data) {
            var name = $("#PrcsName").val().trim();
            var type = data.value;
            if (name == "") {
                exLayer.yellowSighMsg("请输入名称");
                return false;
            }
            exUtils.ajax("/SysBasic/AutoCode/CreatCode", "post", { name: name, type: type }, true).done(function (response) {
                $("#PrcsNo").val(response.extra);
            }).fail(function (error) {
                console.log(error);
            });
            return false;
        });

        //所有可写字段
        $('#allPrcsIndex').on('click', function () {
            $('#PrcsIndex').val("#all#");
            $('#PrcsIndex_Exa').val("所有");

        });
        //可写字段
        $('#PrcsIndex2').on('click', function () {
            exLayer.open("可写字段", "/Com/ComSelect/SelectIndexAndSonTb?fId=flowprcs01&tbid=" + $("#tbid").val() + "&sId=" + $("#PrcsIndex").val(), '100%', '100%', '0px', '0px', null, null);
        });

        //保密字段
        $('#HiddenIndex2').on('click', function () {
            exLayer.open("保密字段", "/Com/ComSelect/SelectIndexAndSonTb?fId=flowprcs02&tbid=" + $("#tbid").val() + "&sId=" + $("#PrcsIndex").val(), '100%', '100%', '0px', '0px', null, null);
        });

        //所有用户
        $('#allPrcsUser').on('click', function () {
            $('#PrcsUser').val("#all#");
            $('#PrcsUser_Exa').val("所有用户");

        });
        //选择用户
        $('#PrcsUser2').on('click', function () {
            exLayer.open("选择用户", "/Com/ComSelect/SelectUser?fId=flowprcs&sId=" + $("#PrcsUser").val(), '100%', '100%', '0px', '0px', null, null);
        });

        //所有部门
        $('#allPrcsDept').on('click', function () {
            $('#PrcsDept').val("#all#");
            $('#PrcsDept_Exa').val("所有部门");

        });
        //选择部门
        $('#PrcsDept2').on('click', function () {
            exLayer.open("选择部门", "/Com/ComSelect/SelectDept?fId=flowprcs&sId=" + $("#PrcsDept").val(), '100%', '100%', '0px', '0px', null, null);
        });

        //所有角色
        $('#allPrcsPriv').on('click', function () {
            $('#PrcsPriv').val("#all#");
            $('#PrcsPriv_Exa').val("所有角色");
        });
        //选择角色
        $('#PrcsPriv2').on('click', function () {
            exLayer.open("选择角色", "/Com/ComSelect/SelectRole?fId=flowprcs&sId=" + $("#PrcsPriv").val(), '100%', '100%', '0px', '0px', null, null);
        });
    });
</script>